﻿@model IEnumerable<FreeDAM.Domain.Entities.Asset>
@{
    ViewBag.Title = "Assets";
    FreeDAM.Domain.Entities.Rendition thumbnailImage;
    FreeDAM.Domain.Entities.Rendition previewImage;
}

<div>
    <div>
        <h2>Assets</h2>
    </div>
</div>
<div>
    <div>
        @Html.ActionLink("Upload New »", "Upload", null, new { @class = "small button" })
    </div>
</div>
<div id="asset-index">
    <div>
    @foreach (FreeDAM.Domain.Entities.Asset asset in Model)
    {
        if (asset.MimeType.Contains("audio"))
        {
            <div class="asset-item">
                <audio controls="controls">
                    @if (asset.FileName.Contains(".mp3") || asset.FileName.Contains(".ogg"))
                    {
                        <source type="@asset.MimeType" src="@Url.Content(asset.ServerRelativePath)" />
                    }
                    @foreach (FreeDAM.Domain.Entities.Rendition rendition in asset.Renditions)
                    {
                        <source type="@rendition.MimeType" src="@Url.Content(rendition.ServerRelativePath)" />
                    }
                </audio>
                <div>@asset.FileName</div>
                <div>@((asset.Renditions == null) ? 0 : asset.Renditions.Count)</div>
                <div>@Html.ActionLink("Details", "Details", new { id = asset.Id })</div>
            </div>
        }
        else if (asset.MimeType.Contains("video"))
        {
            //Video should pop out at 600x400
            thumbnailImage = asset.Renditions.SingleOrDefault(r => r.Tags.Count(t => t.Name == "Thumbnail") == 1);
            <div class="asset-item">
                <div>
                    <a class="fancybox.ajax fancybox-video" href="@Url.Action("Preview", "Assets", new { id = asset.Id })">
                        <img src="@((thumbnailImage == null) ? Url.Content("~/Images/thumbnailRendering.jpg") : Url.Action("Thumbnail", "Files", new { id = thumbnailImage.Id }))" alt="@asset.Name" />
                    </a>
                </div>
                <div>@asset.FileName</div>
                <div>@((asset.Renditions == null) ? 0 : asset.Renditions.Count)</div>
                <div>@Html.ActionLink("Details", "Details", new { id = asset.Id })</div>
            </div>
        }
        else
        {
            thumbnailImage = asset.Renditions.SingleOrDefault(r => r.Tags.Count(t => t.Name == "Thumbnail") == 1);
            previewImage = asset.Renditions.SingleOrDefault(r => r.Tags.Count(t => t.Name == "Preview") == 1);
            <div class="asset-item">
                <div>
                    <a class="fancybox-image fancybox.ajax" href="@((previewImage == null) ? Url.Content("~/Images/thumbnailRendering.jpg") : Url.Action("DisplayRendition", "Files", new { id = previewImage.Id }))">
                        <img src="@((thumbnailImage == null) ? Url.Content("~/Images/thumbnailRendering.jpg") : Url.Action("Thumbnail", "Files", new { id = thumbnailImage.Id }))" alt="@asset.Name" />
                    </a>
                </div>
                <div>@asset.FileName</div>
                <div>@((asset.Renditions == null) ? 0 : asset.Renditions.Count)</div>
                <div>@Html.ActionLink("Details", "Details", new { id = asset.Id })</div>
            </div>
        }
    }
    </div>
</div>
<script type="text/javascript">
    $().ready(function () {
        $('video,audio').mediaelementplayer({
            plugins: ['flash','silverlight'],
            pluginPath: GetPath('/Content')
        });
    });
</script>